package SingleListPractice;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        LinkedList<Integer> list = new LinkedList<>(arrayList);

        System.out.println(list);
        LinkedList<Integer> list2 = new LinkedList<>();
        list2.add(10);//默认他是尾插法
        list2.add(20);
        list2.add(30);
        list2.add(2, 19);

        System.out.println(list2);

        System.out.println("============");

        for (Integer x : list2) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("======ListIterator======");
        ListIterator<Integer> listIterator = list2.listIterator();
        while (listIterator.hasNext()) {
            System.out.print(listIterator.next() + " ");
        }
        System.out.println();
        System.out.println("======ListIterator2======");
        ListIterator<Integer> listIterator2 = list2.listIterator(list2.size());
        while (listIterator2.hasPrevious()) {
            System.out.print(listIterator2.previous() + " ");
        }
        System.out.println();
    }
    public static void main2(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addLast(1);
        myLinkedList.addLast(2);
        myLinkedList.addLast(1);
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(4);
        myLinkedList.addFirst(1);
        myLinkedList.display();
        System.out.println(myLinkedList.size());
        myLinkedList.addIndex(1,100);
        myLinkedList.display();
        myLinkedList.removeAllKey(1);
        myLinkedList.display();
        myLinkedList.clear();
        myLinkedList.display();
    }
    public static void main1(String[] args) {
        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(12);
        mySingleList1.addLast(22);
        mySingleList1.addLast(32);
        mySingleList1.addLast(42);
        mySingleList1.addLast(52);
        mySingleList1.display();
        System.out.println();
        MySingleList mySingleList2 = new MySingleList();
        mySingleList2.addLast(13);
        mySingleList2.addLast(45);
        mySingleList2.addLast(67);
        mySingleList2.addLast(89);
        mySingleList2.addLast(90);
        mySingleList2.display();
        System.out.println();
        MySingleList.ListNode newHead = MySingleList.mergeTwoLists(mySingleList1.head,mySingleList2.head);
        mySingleList1.display(newHead);
    }
}
